#include "comm.hpp"
#include "log.hpp"

int main(){
    int shmid = createShm();
    // comlog(Debug, "createshm success");

    char* shmaddr = (char*)shmat(shmid, nullptr, 0);
    // comlog(Debug, "shmat success");

    mypipe p;
    int fd = open(FILEPATH, O_RDONLY);
    if(fd < 0){
        comlog(Fatal, "open error,error string: %s, error code: %d", strerror(errno), errno);
        exit(1);
    }
    while(1){
        char ser;
        int n = read(fd, &ser, 1);
        if(n < 0){
            comlog(Fatal, "read error,error string: %s, error code: %d", strerror(errno), errno);
            break;
        }
        else if(n == 0){
            comlog(Info, "read done");
            break;
        }
        cout << "memory2 say:" << shmaddr << endl;
    }

    shmdt(shmaddr);
    comlog(Debug, "shmdt success");

    shmctl(shmid, IPC_RMID, nullptr);
    comlog(Debug, "shmctl success");
    close(fd);
    return 0;
}